package com.hgd.action;

import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Map;

import org.apache.struts2.interceptor.RequestAware;
import org.apache.struts2.json.annotations.JSON;

import com.opensymphony.xwork2.ActionSupport;

public class StockPrice extends ActionSupport{
	
	private String dataParameters = null;
	
	public String getPrice(){	
		System.out.println("111");
		int lowerLimit = 30;
		int upperLimit = 35;
		//Generate a random value - between lower and upper limits
		double randomValue = Math.random()*100*(upperLimit-lowerLimit)/100+lowerLimit;
		// Next few steps, to round this double to 2 decimal places
		long factor = (long)Math.pow(10,2);
		// Shift the decimal the correct number of places
		// to the right.
		randomValue = randomValue * factor;
		// Round to the nearest integer.
		long tmp = Math.round(randomValue);
		// Shift the decimal the correct number of places
		// back to the left.
		double roundedRandomValue=(double)tmp / factor;
		//Get label for the data - time in format HH:mm:ss
		Calendar cal = Calendar.getInstance();
		SimpleDateFormat sdf = new SimpleDateFormat("HH:mm:ss");
		String timeLabel = sdf.format(cal.getTime());
		dataParameters = "&label=" +timeLabel+ "&value=" +roundedRandomValue;
		System.out.println(dataParameters);
		return SUCCESS;
	}
	@JSON(name="dataParameters") 
	public String getDataParameters() {
		return dataParameters;
	}
	public void setDataParameters(String dataParameters) {
		this.dataParameters = dataParameters;
	}

	
}
